﻿//-----------------------------------------------------------------
//
// @(#)$Id: ReBuilderReasonDetail.aspx.cs,v 1.0 2013/12/13 17:38:52 lichunhua Exp $
// @(#)$Author: lichunhua  $
// @(#)$Date: 2013/12/13 17:38:52 $
// @(#)$Description:
//
//
//
//                 All Rights Reserved.
//-----------------------------------------------------------------
using System;
using System.Data;
using ebay.Dal.CenterDB_BasTableAdapters;

public partial class UI_Bas_ReBuilderReasonDetail : System.Web.UI.Page
{
    static string act = "";
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            act = Request.QueryString["act"];
            if (!string.IsNullOrEmpty(act))
            {
                switch (act)
                {
                    case "I":
                        txtMtime .Value = DateTime.Now.ToString();
                        break;
                    case "U":
                        {
                            this.txtId.Attributes["readonly"] = "readonly";
                            string Id =Request.QueryString["id"];
                            T_ReBuilderReasonTableAdapter reason=new T_ReBuilderReasonTableAdapter ();                        
                            DataTable dt = reason.GetDataById(Id);
                            DataRow r = dt.Rows[0];
                            txtId.Value = r["Id"].ToString();
                            txtReBuilderReason.Value = r["ReBuilderReason"].ToString();
                            txtMnote.Value = r["Mnote"].ToString();
                            txtMtime.Value = r["Mtime"].ToString();                             
                        }
                        break;
                }
            }
        }
    }
    protected void btnSave_Click(object sender, EventArgs e)
    {
        
        if (Session["UserId"] == null)
        {
            WebUtility.ShowMsg("登陆超时,请重新登陆", this);
            return;
        }
        string userid = Session["UserId"].ToString();
        if (!string.IsNullOrEmpty(act))
        {
            switch (act)
            {
                case "I":
                    {
                        T_ReBuilderReasonTableAdapter reason = new T_ReBuilderReasonTableAdapter();
                        int flag = int.Parse(reason.IsExists(txtId.Value).ToString());
                        if (flag == 0)
                        {
                            int val = reason.Insert(
                                     txtId.Value,
                                     txtReBuilderReason.Value,
                                     txtMnote.Value,
                                     userid,
                                     Convert.ToDateTime(txtMtime.Value),
                                     "",
                                     new DateTime(1900, 1, 1)
                                     );
                            if (val > 0)
                            {
                                Response.Write("<script>alert('添加成功!');window.location.href='ReBuilderReason.aspx'</script>");
                            }
                        }
                        else
                        {
                            Response.Write("<script>alert('编号重复!...');</script>");
                        }
                    }
                    break;
                case "U":
                    {
                        T_ReBuilderReasonTableAdapter reason = new T_ReBuilderReasonTableAdapter();                       
                        int val = reason.Update(                  
                                     txtReBuilderReason.Value,
                                     txtMnote.Value,
                                     userid,
                                     Convert.ToDateTime(txtMtime.Value),
                                     "",
                                     DateTime.Now,
                                     txtId.Value
                                 );                       
                        if (val > 0)
                        {
                            Response.Write("<script>alert('修改成功!');window.location.href='ReBuilderReason.aspx'</script>");
                        }
                    }
                    break;
                default:
                    break;
            }
        }
    }
}